import QtQuick 1.0

MouseArea {
    width: screen.width
    height: screen.height
    anchors.centerIn: parent

    onClicked: {
        menu.opacity = 1;
        loader.source = ""
    }

    Rectangle {
        anchors.fill: parent
        opacity: 0.4
        color: "black"
    }

    Flickable {
        id: infoViewFlickable

        property bool copyrightNoticeVisible: false

        width: parent.width * 0.5
        height: parent.height
        anchors.centerIn: parent
        contentHeight:
            infoViewFlickable.copyrightNoticeVisible ? 2000 :
                infoText.height
                + copyrightText.height
                + 1.5 * okButton.height;

        Text {
            id: infoText

            y: screen.height * 0.1
            anchors { left: parent.left }
            visible: infoViewFlickable.copyrightNoticeVisible ? 0 : 1;
            color: textColor
            width: parent.width
            wrapMode: Text.WordWrap
            textFormat: Text.RichText
            font.pixelSize: screen.height * 0.05

            text: "<b><h2>Moto Trial Racer 1.0</b></h2>" +
                  "Moto Trial Racer is a Nokia example that " +
                  "demonstrates integrating QML " +
                  "to Box2D. See more information " +
                  "about the project at <a href=\"https://projects." +
                  "forum.nokia.com/mototrialracer\">https://projects." +
                  "forum.nokia.com/motortrialracer</a>." +
                  "<h3>Playing Moto Trial Racer</h3>" +
                  "<p>The Goal is to get the motorcycle and the driver " +
                  "to the chequered flag as fast as possible." +
                  "The game ends if any part of the motorcycle or player " +
                  "touches the spikes or the player's head touches " +
                  "any other object. When the player gets to the " +
                  "chequered flag fast enough, he/she gets his/her " +
                  "name and time to the high scores list. " +
                  "The game can be paused, restarted and exited at any time " +
                  "via the options menu. </p>" +
                  "<h3>Controls</h3>" +
                  "<p>The motorcycle is accelerated by leaning the device " +
                  "towards the player and braked by leaning the device away " +
                  "from the player. The center of mass can be moved " +
                  "backwards/forwards by tilting the device left/right.</p>";
            onLinkActivated: Qt.openUrlExternally(link)
        }

        Text {
            id: copyrightText

            anchors {
                topMargin: 20
                top: infoText.bottom
                left: parent.left
            }

            visible: infoViewFlickable.copyrightNoticeVisible ? 0 : 1;
            color: textColor
            width: parent.width
            wrapMode: Text.WordWrap
            textFormat: Text.RichText
            font.pixelSize: screen.height * 0.05

            text: "<h3>Copyright Notices</h3>" +
                  "<p>This software includes certain parts under the GNU " +
                  "Lesser General Public License, version 2.1 (LGPL) and " +
                  "other licenses. <b>Please tap here for applicable " +
                  "copyright- and other notices, permissions, and " +
                  "acknowledgements.</b></p>";

            MouseArea {
                anchors.fill: parent

                onClicked: {
                    infoViewFlickable.copyrightNoticeVisible = true;
                    infoViewFlickable.contentY = 0;
                }
            }
        }

        CopyrightNotice {
            id: copyrightNotice

            y: screen.height * 0.1
            width: parent.width
            visible: infoViewFlickable.copyrightNoticeVisible ? 1 : 0;
            onBackPressed: infoViewFlickable.copyrightNoticeVisible = false;
            onTextChanged: infoViewFlickable.contentY = 0;
        }

        Button {
            id: okButton
            name: "ok"
            visible: !infoViewFlickable.copyrightNoticeVisible

            anchors {
                top: copyrightText.bottom;
                horizontalCenter: parent.horizontalCenter
            }

            onClicked: {
                menu.opacity = 1;
                loader.source = ""
            }
        }
    }
}
